
//去掉前后空格

function deltrim(x){
	while(x.length>0 && x.charAt(0)==' ')
	 	x = x.substring(1,x.length);
	while(x.length>0&&x.charAt(x.length-1)==' ')
		x = x.substring(0,x.length-1);
	return x;
}

//非空验证

function isNull(elem,message){
	var va=deltrim(elem.value);
	if(va==""){
		alert(message);
		elem.focus();
		return false;
	}
	return true;
}

//验证账号

function validateId(){
	var first=document.forms[0].name.value.charAt(0);
	var exp=/^[a-z0-9]+$/;
	if(isNull(document.forms[0].name,"请输入用户名")){//验证非空
		//验证首字符
		return true;
	}else{
		return false;
	}
}

//验证密码

function validatepwd(){
	var exp=/^[a-z0-9]+$/;
	if(isNull(document.forms[0].pwd,"请输入密码")){//验证非空
		if(document.forms[0].pwd.value.length<=8){
			alert("密码大于8位");
			document.forms[0].pwd.focus();
			return false;
		}else{
			if(exp.test(document.forms[0].pwd.value)){
				alert("密码需要有字母和数字之外的字符!");
				document.forms[0].pwd.focus();
				return false;
			}
		}
	}else{
		return false;
	}
	return true;
}

//提交按钮

function gogo(){
	if(validateId()    &&   validatepwd()){
		document.forms[0].submit();
		return true;
	}
	return false;
}
